//
//  DNNotificationDaoTests.m
//  DanoneEA
//
//  Created by Senela on 16/11/3.
//  Copyright © 2016年 翔傲科技. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "DNNotificationDao.h"

@interface DNNotificationDaoTests : XCTestCase
{
    DNNotificationModel  *model;
    DNNotificationModel  *model1;
}
@end

@implementation DNNotificationDaoTests

- (void)setUp {
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
    
    model = [[DNNotificationModel alloc] init];
    model.serverId = [NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]];
    model.createTime =[NSString stringWithFormat:@"%.0f", [[NSDate date] timeIntervalSince1970]];
    model.type = NotifyType_Stool;
    model.mode = NotifyMode_Daily;
    model.time = @"2016-11-20";
    
    
    model1 = [[DNNotificationModel alloc] init];
    model1.serverId = [NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]];
    model1.createTime =[NSString stringWithFormat:@"%.0f", [[NSDate date] timeIntervalSince1970]];
    model1.type = NotifyType_Stool;
    model1.mode = NotifyMode_Interval;
    model1.time = @"10";
}

- (void)tearDown {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

- (void)testExample {
    // This is an example of a functional test case.
    // Use XCTAssert and related functions to verify your tests produce the correct results.
}

- (void)testPerformanceExample {
    // This is an example of a performance test case.
    [self measureBlock:^{
        // Put the code you want to measure the time of here.
    }];
}

-(void)test1AddSuc
{
    [[DNDataBase shareInstance] clearAllTableData];
    
    // 场景一：成功－新增 model
    BOOL ret = [[DNNotificationDao shareInstance] saveNotificationModel:model];
    XCTAssertEqual(ret, YES, @"saveNotificationModel error! appId:%@", model.serverId);
}

// 场景二：失败－ 新增时间冲突的model
-(void)test2AddbFail
{
    model1.serverId = nil;
    BOOL ret = [[DNNotificationDao shareInstance] saveNotificationModel:model1];
    XCTAssertEqual(ret, NO, @"saveNotificationModel without serverId error! appId:%@", model.serverId);
}


-(void)test3ModifySuc
{
    // 场景三：成功－ 编辑model后进行存储
    model.mode = NotifyMode_Interval;
    model.time = @"8";
    
    BOOL ret = [[DNNotificationDao shareInstance] saveNotificationModel:model];
    XCTAssertEqual(ret, YES, @"saveNotificationModel error! appId:%@", model.serverId);
    
}


-(void)test4ModifyFail4
{
    model.serverId = nil;
    BOOL ret = [[DNNotificationDao shareInstance] saveNotificationModel:model];
    XCTAssertEqual(ret, NO, @"modify NotificationModel without serverId error! serverId:%@", model.serverId);
    
}

-(void)test5DeleteSuc
{
    BOOL ret = [[DNNotificationDao shareInstance] deleteNotificationModel:model];
    XCTAssertEqual(ret, YES, @"delete NotificationModel failed! serverId:%@", model.serverId);
}

-(void)test6SaveArr
{
    [[DNDataBase shareInstance] clearAllTableData];
    
    NSMutableArray *notificationArr = [NSMutableArray array];
    NSTimeInterval timeInterval =  [[NSDate date] timeIntervalSince1970];
    for(int i=0; i<20; i++)
    {
        DNNotificationModel  *notificationTempInfo = [[DNNotificationModel alloc] init];
        
        notificationTempInfo.serverId =[NSString stringWithFormat:@"%.0f", timeInterval - i];
        notificationTempInfo.createTime =[NSString stringWithFormat:@"%.0f", timeInterval - i];
        notificationTempInfo.type = NotifyType_Feeding;
        notificationTempInfo.mode = NotifyMode_Daily;
        notificationTempInfo.time = @"2016-11-20";
        
        [notificationArr addObject: notificationTempInfo];
    }
    
    
    BOOL ret =[[DNNotificationDao shareInstance] saveNotificationArr:notificationArr];
    XCTAssertEqual(ret, YES, @"DNNotificationDao-- saveNotificationArr error");
    
    for(int i=20; i<30; i++)
    {
        DNNotificationModel  *notificationTempInfo = [[DNNotificationModel alloc] init];
        
        notificationTempInfo.serverId =[NSString stringWithFormat:@"%.0f", timeInterval - i];
        notificationTempInfo.createTime =[NSString stringWithFormat:@"%.0f", timeInterval - i];
        notificationTempInfo.type = NotifyType_Stool;
        notificationTempInfo.mode = NotifyMode_Daily;
        notificationTempInfo.time = @"2016-11-20";
        
        [notificationArr addObject: notificationTempInfo];
    }
    
    
    ret =[[DNNotificationDao shareInstance] saveNotificationArr:notificationArr];
    XCTAssertEqual(ret, YES, @"DNNotificationDao-- saveNotificationArr error");
    
    
    NSMutableArray *dispalyArr = [[DNNotificationDao shareInstance] getAllNotificationArr];
    XCTAssertEqual(dispalyArr.count, 30, @"DNCryingManager-- getAllNotificationArr error");
                                  
    NSMutableArray *feedNotificationArr = [[DNNotificationDao shareInstance] getNotificationArrByType:NotifyType_Feeding];
    XCTAssertEqual(feedNotificationArr.count, 20, @"DNCryingManager-- getNotificationArrByType error");
    
    NSMutableArray *stoolNotificationArr = [[DNNotificationDao shareInstance] getNotificationArrByType:NotifyType_Stool];
    XCTAssertEqual(stoolNotificationArr.count, 10, @"DNCryingManager-- getNotificationArrByType error");
}


@end
